using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;
using Preparation;
using Tester.Forms;

namespace Tester.GuiActions.Actions.Impl
{
    public class ImportFileAction : BaseAction
    {
        public override bool Visible
        {
            get
            {
                return (TesterMultyDocument.Instance == null || 
                      TesterMultyDocument.Instance.Suspended == TesterMultyDocument.SuspendStates.Stopped) &&
                    TesterMainForm.Instance.TopControl == EmbededControlTags.StartWork ||
                    TesterMainForm.Instance.TopControl == EmbededControlTags.TesterList;
            }
        }

        public override void MainAction(object sender, EventArgs e)
        {
            if (TesterList.Instance != null)
            {
                DialogResult result = MessageBox.Show("Close current document?", "Document", MessageBoxButtons.YesNoCancel);
                switch (result)
                {
                    case DialogResult.Cancel:
                    case DialogResult.No:
                        return; 
                    case DialogResult.Yes:                            
                        Actions.Instance.ActionsManager.ActionByName("close_file").MainAction(null, null);
                        break;
                }
            }
            OpenFileDialog dlg = new OpenFileDialog();
            dlg.ShowDialog();
            if (!String.IsNullOrEmpty(dlg.FileName))
            {
                try
                {
                    OldDoc doc = new OldDoc(dlg.FileName);
                    TesterMultyDocument.Import(doc);
                }
                catch (Exception e1)
                {
                    MessageBox.Show(e1.ToString(), "Error");
                }
            }
        }

    }
}
